package com.zoffy.oj_backend.controller;

import com.zoffy.oj_backend.model.vo.UserVo;
import com.zoffy.oj_backend.service.UserService;
import com.zoffy.oj_backend.utils.SSEUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

@RestController
@RequestMapping("/sse")
public class SSEController {
    @Resource
    private UserService userService;
    @GetMapping(value = "/subscribe")
    public SseEmitter subscribe(HttpServletRequest request){
        UserVo userVo = userService.currentUserVo(request);
        String userId = String.valueOf(userVo.getId());
        return SSEUtils.subscribe(userId);
    }
}
